package com.bw.test;

import org.junit.Test;

import java.time.LocalDateTime;
import java.time.temporal.ChronoUnit;

public class Exercise {
    @Test
    //计算一天还剩多少时间的方法
    public void exerciseDate(){
        //LocalDateTime和ChronoUnit为1.8新增
        LocalDateTime midnight = LocalDateTime.now().plusDays(1).withHour(0).withMinute(0).withSecond(0).withNano(0);
        long millSeconds = ChronoUnit.MILLIS.between(LocalDateTime.now(),midnight);
        long seconds = ChronoUnit.SECONDS.between(LocalDateTime.now(), midnight);
        System.out.println("当天剩余毫秒：" + millSeconds);
        System.out.println("当天剩余秒：" + seconds);

    }
}
